package com.ailk.aee.pcc.server;

import com.ailk.aee.pcc.dao.UserPloyDao;
import com.mongodb.BasicDBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * @author chencaho
 */
@Service
public class UserPloyServer {


    @Autowired
    private UserPloyDao userPloyDao;


    public boolean isInvoled(String userId, String ployId) throws Exception {
        BasicDBObject pccPloy = this.query(userId);
        if (null == pccPloy) {
            return false;
        }
        return pccPloy.containsField(ployId);
    }

    public BasicDBObject query(String userId) throws Exception {
        BasicDBObject pccPloy  = (BasicDBObject)userPloyDao.queryOne(userId);
        return pccPloy;
    }

    public void insert(String userId, String ployId ) throws Exception {
        if (!isInvoled(userId, ployId)) {
            // 保存mongodb
            userPloyDao.insertToMongo(userId, ployId  );
        }
    }


    public void delete(String userId, String ployId) throws Exception {
        // 删除mongodb
        userPloyDao.deleteToMongo(userId, ployId);
    }

}
